<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>商城后台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.5.5/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/layui_ext/dtree/dtree.css}" >
    <link rel="stylesheet" th:href="@{/lib/layui_ext/dtree/font/dtreefont.css}" >
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>

<span th:replace="common_page::common"></span>

<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">颜色名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" maxlength="30" lay-reqtext="不能为空" placeholder="请输入颜色名称" value="" class="layui-input">
            <tip>填写颜色名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">选择颜色</label>
        <div class="layui-input-block">
            <div id="selectColor"></div>
            <input type="hidden" name="rgbColor" id="rgbColor" />
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea name="remark" class="layui-textarea" maxlength="255" placeholder="请输入备注信息"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script th:src="@{/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['colorpicker','form'], function () {
        var form = layui.form,
            layer = layui.layer,
            colorpicker = layui.colorpicker,
            $ = layui.$;

        //常规使用
        colorpicker.render({
            elem: '#selectColor' //绑定元素
            ,change: function(color){ //颜色改变的回调
                $("#rgbColor").val(color);
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                url:"[[@{/colorTable/save}]]",
                contentType: "application/json; charset=utf-8",
                type:'POST',
                data:JSON.stringify(data.field),
                success:function(data){
                    if(data.code<=0) {
                        layer.msg(data.msg);
                        return false;
                    }
                    var index = layer.alert(data.msg, {
                        title: '提示信息'
                    }, function () {
                        // 关闭弹出层
                        layer.close(index);
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(iframeIndex);

                    });
                }
            });
            return false;
        });



    });
</script>
</body>
</html>